package com.hq.sp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/*
* 重要！如果你的项目引入junit测试，此处需要使用@WebAppConfiguration，如果没有使用junit使用
@Configuration
*/
@Configuration
@EnableSwagger2 // 重要！
// 如果要访问的话直接访问 http://localhost:8080/项目名称/swagger-ui.html 就可以访问到文档了
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hq.sp.controller"))
                .paths(PathSelectors.any())
                .build();
// .securityContexts(securityContexts())
// .securitySchemes(securitySchemes());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("进销存系统-接口-测试文档")
                .description("接口测试文档")
                .contact(new Contact("作者", "url", "xxx@qq.com"))
                .version("1.0")
                .build();
    }
}
